package helexis.game.tyrian.screen;

import static com.badlogic.gdx.scenes.scene2d.actions.Actions.fadeIn;
import static com.badlogic.gdx.scenes.scene2d.actions.Actions.sequence;
import helexis.game.tyrian.Tyrian;
import helexis.game.tyrian.domain.Level;
import helexis.game.tyrian.domain.Profile;
import helexis.game.tyrian.screen.scene2d.Ship2D;
import helexis.game.tyrian.service.MusicManager.TyrianMusic;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;

public class LevelScreen extends AbstractScreen {
	
	/**
	 * 게임 Profile
	 */
	private Profile profile;
	/**
	 * 게임 레벨
	 */
	private Level level;
	
	/**
	 * 2D 비행선
	 */
	private Ship2D ship2d;
	
	
	public LevelScreen(Tyrian game, int levelId) {
		
		super(game);
		
		this.profile = game.getProfileManager().retrieveProfile();
		this.level = game.getLevelManager().findLevelByLevelId(levelId);
		
	}//end of constructor()
	
	
	@Override
	protected boolean isGameScreen() {
		return true;
	}//end of isGameScreen()
	
	
	
	@Override
	public void show() {

		super.show();
		
		/*
		 * 레벨 음악 플레이!
		 */
		game.getMusicManager().play(TyrianMusic.LEVEL);
		
		
		/*
		 * 2D 비행선을 만든다.
		 */
		this.ship2d = Ship2D.create(profile.getShip(), atlas);
		
		/*
		 * 초기 비행선 위치 설정 (화면 하단 가운데)
		 */
		Gdx.app.log(Tyrian.LOG, "Stage width : " + stage.getWidth());
		Gdx.app.log(Tyrian.LOG, "Ship width : " + this.ship2d.getWidth());
		Gdx.app.log(Tyrian.LOG, "Ship position-X : " + ((stage.getWidth() / 2) - (this.ship2d.getWidth() / 2)));
		
		this.ship2d.setX((stage.getWidth() / 2) - (this.ship2d.getWidth() / 2));
		this.ship2d.setY(this.ship2d.getHeight());
		
		/*
		 * 스테이지 위에 2D 비행선 추가
		 */
		stage.addActor(this.ship2d);
		
		/*
		 * 스테이지 색깔 지정 및 효과 추가
		 */
		stage.getRoot().setColor(Color.BLACK);
		stage.getRoot().addAction(sequence(fadeIn(0.5f)));
		
	}//end of show()
	

}
//end of LevelScreen.java